import React, { Component } from 'react'
import '../../assets/css/register.css'
import {login1} from '../../request/api'
import { message} from 'antd';
export default class login extends Component {
    constructor(){
        super()
        this.state={
            user:{
                phone:'',
                password:''
            }
        }
    }
    change(e,type){
        this.setState({user:{
            ...this.state.user,
            [type]:e.target.value
        }})
    }
    login(){
        if(this.state.user.phone!=""&&this.state.user.password!=""&&this.state.user.nickname!=""){
  
               login1(this.state.user).then(res=>{
        if(res.code==200){
            console.log(res);
            let a=JSON.stringify(res.list)
            sessionStorage.setItem('user',a)
            message.success(res.msg);
            this.props.history.push('/index/home')
        }else {
            message.error(res.msg);
        }
        
    })
       }else {
           message.info('请填写完整');
       }
    
    }
    render() {
        return (
            <div>
                <div className='register'>
                <div className='register-top'><i onClick={()=>this.props.history.goBack()}>&lt;</i> 手机登录 <span className='register1' onClick={()=>this.props.history.push('/register')}>注册</span></div>
                <img src="/img/log.png" alt="" />
                <div className='cont'>
                   <label htmlFor="">手机号</label> <input type="text" name="" id="" value={this.state.user.phone} onChange={(e)=>this.change(e,'phone')}/><br />
                   <label htmlFor="">密&nbsp; &nbsp;码</label><input type="password" name="" id="" value={this.state.user.password} onChange={(e)=>this.change(e,'password')}/><br />
                    <button onClick={()=>this.login()}>登录</button>
                </div>
            </div>
            </div>
        )
    }
}
